<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initView()
    {
        Zend_Session::start();
        $this->bootstrap('layout');
        $layout = $this->getResource('layout');
        $view = $layout->getView();
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=utf-8');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/css/base.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/js/slider/jquery.bxslider.css', 'screen');
        $view->headLink()->appendStylesheet($view->baseUrl() . '/js/lightbox/prettyPhoto.css', 'screen');
//         JS
        $view->headScript()->appendFile('http://code.jquery.com/jquery-latest.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/base.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/lightbox/jquery.prettyPhoto.js');
        $view->headScript()->appendFile('http://html5shiv.googlecode.com/svn/trunk/html5.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/slider/jquery.bxslider.min.js');
        $view->headScript()->appendFile($view->baseUrl() . '/js/tinymce.min.js');
        $view->headTitle('"Труд-Сервис" - продажа, ремонт и аренда строительного оборудования г. Кировск');
        $view->headTitle()->setSeparator(' | ');
        $view->headTitle()->setDefaultAttachOrder(Zend_View_Helper_Placeholder_Container_Abstract::PREPEND);
        Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
    }

    public function _initRoute()
    {
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');
        $router = $front->getRouter();

        $router->addRoute(
            'sanitary',
            new Zend_Controller_Router_Route('/sanitary/',
                array(
                    'controller' => 'catalog',
                    'action' => 'sanitary'
                )
            )
        );
        $router->addRoute(
            'electric',
            new Zend_Controller_Router_Route('/electric/',
                array(
                    'controller' => 'catalog',
                    'action' => 'electric'
                )
            )
        );
        $router->addRoute(
            'builder',
            new Zend_Controller_Router_Route('/builder/',
                array(
                    'controller' => 'catalog',
                    'action' => 'builder'
                )
            )
        );
        $router->addRoute(
            'contacts',
            new Zend_Controller_Router_Route('/contacts/',
                array(
                    'controller' => 'index',
                    'action' => 'contacts'
                )
            )
        );
        $router->addRoute(
            'login',
            new Zend_Controller_Router_Route('/login/',
                array(
                    'controller' => 'index',
                    'action' => 'login'
                )
            )
        );
        $router->addRoute(
            'logout',
            new Zend_Controller_Router_Route('/logout/',
                array(
                    'controller' => 'index',
                    'action' => 'logout'
                )
            )
        );
        $router->addRoute(
            'service',
            new Zend_Controller_Router_Route('/service/',
                array(
                    'controller' => 'catalog',
                    'action' => 'service'
                )
            )
        );
        $router->addRoute(
            'repair',
            new Zend_Controller_Router_Route('/repair/',
                array(
                    'controller' => 'catalog',
                    'action' => 'repair'
                )
            )
        );
        $router->addRoute(
            'rentCategory',
            new Zend_Controller_Router_Route('/rent/',
                array(
                    'controller' => 'catalog',
                    'action' => 'rent'
                )
            )
        );
        $router->addRoute(
            'rent',
            new Zend_Controller_Router_Route('/rent/:category',
                array(
                    'controller' => 'catalog',
                    'action' => 'rentsbycat'
                )
            )
        );
        $router->addRoute(
            'about',
            new Zend_Controller_Router_Route('/about/',
                array(
                    'controller' => 'index',
                    'action' => 'about'
                )
            )
        );
        $router->addRoute(
            'stock',
            new Zend_Controller_Router_Route('/stock/',
                array(
                    'controller' => 'index',
                    'action' => 'stock'
                )
            )
        );
        $router->addRoute(
            'one_stock',
            new Zend_Controller_Router_Route('/stock/:id',
                array(
                    'controller' => 'index',
                    'action' => 'stock'
                )
            )
        );
        $router->addRoute(
            'useful',
            new Zend_Controller_Router_Route('/useful/',
                array(
                    'controller' => 'index',
                    'action' => 'useful'
                )
            )
        );
        $router->addRoute(
            'one_useful',
            new Zend_Controller_Router_Route('/useful/:id',
                array(
                    'controller' => 'index',
                    'action' => 'useful'
                )
            )
        );
        $router->addRoute(
            'gallery',
            new Zend_Controller_Router_Route('/gallery/',
                array(
                    'controller' => 'index',
                    'action' => 'gallery'
                )
            )
        );
        $router->addRoute(
            'create',
            new Zend_Controller_Router_Route('/admin/create/:form',
                array(
                    'controller' => 'admin',
                    'action'     => 'create'
                )
            )
        );
        $router->addRoute(
            'adminrent',
            new Zend_Controller_Router_Route('/admin/rent/:category',
                array(
                    'controller' => 'admin',
                    'action'     => 'rent'
                )
            )
        );
        $router->addRoute(
            'edit',
            new Zend_Controller_Router_Route('/admin/edit/:form',
                array(
                    'controller' => 'admin',
                    'action'     => 'edit'
                )
            )
        );
        $router->addRoute(
            'delete',
            new Zend_Controller_Router_Route('/admin/delete/:form',
                array(
                    'controller' => 'admin',
                    'action'     => 'delete'
                )
            )
        );
        $router->addRoute(
            'photos',
            new Zend_Controller_Router_Route('/photos/',
                array(
                    'controller' => 'index',
                    'action' => 'photos'
                )
            )
        );
    }

    protected function _initNavigation()
    {
        $config = array(
            Zend_Navigation_Page::factory(
                array(
                    'label' => 'о компании',
                    'uri'   => '/about',
                    'route' => 'about'
                )
            ),
            Zend_Navigation_Page::factory(
                array(
                    'label' => 'акции',
                    'uri'   => '/stock',
                    'route' => 'stock'
                )
            ),

            Zend_Navigation_Page::factory(
                array(
                    'label' => 'полезная информация',
                    'uri'   => '/useful',
                    'class' => 'menu-useful',
                    'route' => 'useful'
                )
            ),

            Zend_Navigation_Page::factory(
                array(
                    'label' => 'галерея',
                    'uri'   => '/gallery',
                    'route' => 'gallery'
                )
            ),

            Zend_Navigation_Page::factory(
                array(
                    'label' => 'контакты',
                    'uri'   => '/contacts',
                    'route' =>'contacts'
                )
            ),

        );

        $container = new Zend_Navigation($config);
        Zend_Registry::getInstance()->set('Zend_Navigation', $container);
    }
}
